/* eslint-disable no-use-before-define */
import axios, {type Paging, type Response} from '@/utils/axios/axios';

/** 得到用户列表 */
export function getAppUserListAxios(data: AppUserListRequest): Promise<Response<Paging<AppUser>>> {
    return axios.get(`/system/appUser/page`, {params: data}) as unknown as Promise<Response<Paging<AppUser>>>;
}

/** 封禁或者正常 */
export function changeStatusAppUserAxios(userId: number): Promise<Response<string>> {
    return axios.post(`/system/appUser/updateStatus`, {userId}) as unknown as Promise<Response<string>>;
}

/** 得到消费记录 */
export function getAppUserConsumptionListAxios(data: AppUserConsumptionListRequest): Promise<Response<Paging<AppUserConsumption>>> {
    const _data: AppUserConsumptionListRequest = JSON.parse(JSON.stringify(data));
    if (![1, 2].includes(data.payType ?? -1)) {
        delete _data.payType;
    }
    if (![1, 2, 3].includes(data.platformType ?? -1)) {
        delete _data.platformType;
    }
    return axios.get(`/system/consumeRecord/page`, {params: _data}) as unknown as Promise<Response<Paging<AppUserConsumption>>>;
}

/** 得到订单列表 */
export function getAppUserSavingsListAxios(data: AppUserSavingsListRequest): Promise<Response<Paging<AppUserSavings>>> {
    const _data: AppUserSavingsListRequest = JSON.parse(JSON.stringify(data));
    if (!['WECHAT', 'ALIPAY'].includes(data.payChannel ?? '')) {
        delete _data.payChannel;
    }

    if (!['juliang', 'cili', 'tengxun', 'xingtu'].includes(data.investmentChannel ?? '')) {
        delete _data.investmentChannel;
    }
    if (!['mp-kuaishou', 'mp-toutiao', 'mp-weixin'].includes(data.orderPlatform ?? '')) {
        delete _data.orderPlatform;
    }
    if (typeof data.isFirstRecharge !== 'number' || ![0, 1].includes(data.isFirstRecharge)) {
        delete _data.isFirstRecharge;
    }
    if (typeof data.status !== 'number' || ![-1, 0, 1, 2, 3, 4].includes(data.status)) {
        delete _data.status;
    }

    return axios.get(`/system/order/page`, {params: _data}) as unknown as Promise<Response<Paging<AppUserSavings>>>;
}

/** 得到订单列表 */
export function getAppUserStarListAxios(data: AppUserSavingsListRequest): Promise<Response<Paging<AppUserSavings>>> {
    const _data: AppUserSavingsListRequest = JSON.parse(JSON.stringify(data));
    if (!['WECHAT', 'ALIPAY'].includes(data.payChannel ?? '')) {
        delete _data.payChannel;
    }

    if (!['juliang', 'cili', 'tengxun', 'xingtu'].includes(data.investmentChannel ?? '')) {
        delete _data.investmentChannel;
    }
    if (!['mp-kuaishou', 'mp-toutiao', 'mp-weixin'].includes(data.orderPlatform ?? '')) {
        delete _data.orderPlatform;
    }
    if (typeof data.isFirstRecharge !== 'number' || ![0, 1].includes(data.isFirstRecharge)) {
        delete _data.isFirstRecharge;
    }
    if (typeof data.status !== 'number' || ![-1, 0, 1, 2, 3, 4].includes(data.status)) {
        delete _data.status;
    }

    return axios.get(`/system/weChatMiniOrderApi/wxPage`, {params: _data}) as unknown as Promise<Response<Paging<AppUserSavings>>>;
}

/** 得到订单总金额 */
export function getOrderPriceAllAxios(data: AppUserSavingsListRequest): Promise<Response<{ totalAmount: number }>> {
    return axios.get(`/system/order/getOrderData`, {params: data}) as unknown as Promise<Response<{
        totalAmount: number
    }>>;
}

/** 得到订单总金额（新） */
export function getOrderTotalPriceAxios(data: AppUserSavingsListRequest): Promise<Response<OrderTotalPrice>> {
    return axios.get(`/system/order/totalPrice`, {params: data}) as unknown as Promise<Response<OrderTotalPrice>>;
}

export function getStarOrderTotalPriceAxios(data: AppUserSavingsListRequest): Promise<Response<OrderTotalPrice>> {
    return axios.get(`/system/weChatMiniOrderApi/wxTotalPrice`, {params: data}) as unknown as Promise<Response<OrderTotalPrice>>;
}

export function getWechatPlatformList(): Promise<Response<WechatPlatformList>> {
    return axios.get(`/system/weChatMiniOrderApi/list `, {params: {}}) as unknown as Promise<Response<WechatPlatformList>>;
}

/** 按天查看订单金额 */
export function getOrderTotalAmountData(data: AppUserSavingsListRequest): Promise<Response<Paging<OrderTotalAmountDataItem>>> {
    return axios.get(`/system/order/getOrderTotalAmountData`, {params: data}) as unknown as Promise<Response<Paging<OrderTotalAmountDataItem>>>;
}

/** 根据合作方查询短剧金额 */
export function getPartnerUserData(data: AppUserSavingsListRequest): Promise<Response<Paging<OrderTotalAmountDataItem>>> {
    return axios.get(`/system/order/getPartnerUser`, {params: data}) as unknown as Promise<Response<Paging<OrderTotalAmountDataItem>>>;
}

/** 订单列表数据导出 */
export function orderListExport(data?: any) {
    return axios.get(`/system/order/exportExcel`, {params: data, responseType: 'blob'}) as unknown as Blob;
}

/** 解锁记录 */
export function getDramaUnlockRecord(data: AppDramaUnlockRecord): Promise<Response<Paging<AppUser>>> {
    return axios.get(`/system/dramaUnlockRecord/page`, {params: data}) as unknown as Promise<Response<Paging<AppUser>>>;
}

/** 历史记录 */
export function dramaViewHistoryRecord(data: AppDramaUnlockRecord): Promise<Response<Paging<AppUser>>> {
    return axios.get(`/system/dramaViewHistoryRecord/page`, {params: data}) as unknown as Promise<Response<Paging<AppUser>>>;
}

/** 抖音广告收入列表 */
export function getThirdAdvertEverydayIncome(data: any): Promise<Response<thirdAdvertEverydayIncomePaging<any>>> {
    return axios.get(`/system/thirdAdvertEverydayIncome/page`, {params: data}) as unknown as Promise<Response<thirdAdvertEverydayIncomePaging<any>>>;
}

/** 抖音广告收入更新 */
export function getThirdAdvertEverydayIncomeUpdate(data: any): Promise<Response<thirdAdvertEverydayIncomePaging<any>>> {
    return axios.get(`/system/thirdAdvertEverydayIncome/syncAdvertIncome`, {params: data}) as unknown as Promise<
        Response<thirdAdvertEverydayIncomePaging<any>>
    >;
}

/** 订单列表星图数据导出 */
export function orderExportMonthVideoData(data?: any) {
    return axios.get(`/system/order/exportMonthVideoData`, {params: data, responseType: 'blob'}) as unknown as Blob;
}

/** 平台类型 */
export function socialList(): Promise<Response<Paging<AppUser>>> {
    return axios.get(`/system/social/list`) as unknown as Promise<Response<Paging<AppUser>>>;
}

/** 平台类型 */
export function barCode(data): Promise<Response<string>> {
    return axios.get(`/system/drama/getQrcode`,{params:data}) as unknown as Promise<Response<Paging<AppUser>>>;
}

/** 抖音广告收入列表分页 */
export type thirdAdvertEverydayIncomePaging<T> = {
    income: number;
    incentiveFundCost: number;
    totalIncome: number;
    page: any;
    /** 当前页 */
    current: number;
    /** 数据 */
    records: T[];
    /** 每页数量 */
    size: number;
    /** 总条数  */
    total: number;
};

export type AppUserListRequest = {
    /** 当前页 */
    current: number;
    /** 每页数量 */
    size: number;
    /** 登录账号 */
    username?: string;
    /** 是否VIP：0-否；1-是； */
    isVip?: 0 | 1;
    /** 性别：0-未知；1-男；2-女； */
    sex?: 0 | 1 | 2;
    /** 手机号  */
    phone: string;
    lastSeeDramaTitle?: string;
    referralLinkId?: string;
    referralLinkName?: string;
    userId?: string;
    startDate: string;
    endDate: string;
    /** V1 */
    dramaTitle?: string;
    openId?: string;
};

export type OrderTotalPrice = {
    /**
     * 订单数量
     */
    orderNum: number;
    /**
     * 总金额
     */
    totalAmount: number;
};

export type WechatPlatformList = {
    appCode:string;
    appName: string;
    platformName :  string
};

export type AppDramaUnlockRecord = {
    /** 当前页 */
    current: number;
    /** 每页数量 */
    size: number;
    /** 开始时间 */
    startDate: string;
    /** 结束时间 */
    endDate: string;
    /** 平台类型：1-抖音；2-快手；3-微信； */
    platformType?: 'mp-kuaishou' | 'mp-toutiao' | 'mp-weixin';
    /** 用户登录账号 */
    openId?: string;
    userId?: string;
    dramaTitle?: string;
};

export type AppUserConsumptionListRequest = {
    /** 当前页 */
    current: number;
    /** 每页数量 */
    size: number;
    /** 付费类型：1-现金；2-虚拟币； */
    payType?: 1 | 2;
    /** 平台类型：1-抖音；2-快手；3-微信； */
    platformType?: 1 | 2 | 3;
    /** 用户登录账号 */
    username?: string;
    /** 短剧名称 */
    dramaTitle?: string;
    /** 开始时间 */
    startDate?: string;
    /** 结束时间 */
    endDate?: string;
};

export type AppUserSavingsListRequest = {
    /** 当前页 */
    current: number;
    /** 每页数量 */
    size: number;
    /** 下单平台：mp-kuaishou-快手；mp-toutiao-抖音；mp-weixin-抖音；  */
    orderPlatform?: 'mp-kuaishou' | 'mp-toutiao' | 'mp-weixin';
    /** 订单号 */
    outTradeNo?: string;
    /** 支付渠道：WECHAT-微信；ALIPAY-支付宝； */
    payChannel?: '' | 'ALIPA' | 'WECHAT';
    /** 首充/复冲 */
    isFirstRecharge?: '' | 0 | 1;
    /** 支付状态：-1-异常；0-待支付；1-已支付；2-支付失败；3-已退款；4-已关闭 */
    status?: -1 | '' | 0 | 1 | 2 | 3 | 4;
    /** 短剧ID */
    dramaId?: number;
    /** 短剧名称 */
    dramaTitle?: string;
    /** 充值链接 */
    referralLinkName?: string;
    referralLinkId?: string;
    /** 广告ID */
    promotionId?: string;
    startDate: string;
    endDate: string;
    /** "投广渠道：juliang-巨量；cili-磁力；tengxun-腾讯; xingtu-星图； */
    investmentChannel?: 'cili' | 'juliang' | 'tengxun' | 'xingtu';
    /** 用户id */
    userId: string;
    /** 用户设备系统平台 */
    devicePlatform: string;
    /** 合作方名称 */
    partnerUserName?: string;
    /** 推广模式 */
    iaaFlag?: number;
    /**
     * 微信视频号作者Id
     */
    wxFinderId?: string;
    /**
     * 微信视频号订单
     */
    wxFinderFlag?: string;
    appCode?: string;
    wxFinderOrigin?: string;
};

export type AppUser = {
    /** 头像 */
    avatar: string;
    /** 生日（yyyy-MM-dd） */
    birthday: string;
    /** 收藏短剧数量 */
    collectDramaNum: number;
    /** 是否VIP：0-否；1-是； */
    isVip: 0 | 1;
    /** 昵称  */
    nickname: string;
    /** 累计支付总额  */
    payAmount: number;
    /** 手机号 */
    phone: string;
    /** 性别：0-未知；1-男；2-女； */
    sex: 0 | 1 | 2;
    /** 用户ID  */
    userId: number;
    /** 状态(0-正常,1-冻结) */
    status: 0 | 1;
    /** 登录账号  */
    username: string;
    /** vip到期时间   */
    vipExpireTime: string;
    /** 虚拟币数 */
    virtualCoins: number;
    /** 观看记录 */
    lastPayDramaTitle: string | null;
    /** 最近观看时间 */
    lastSeeTime: string | null;
    /** 最近充值行为 */
    lastUserPayAction: string | null;
    /** 最近充值金额 */
    lastUserPayMoney: number | null;

    /** V1 */
    /**
     * 最后观看短剧集数
     */
    lastSeeDramaSeq?: number;
    /**
     * 最后观看短剧名称
     */
    lastSeeDramaTitle?: string;
};

export type AppUserConsumption = {
    /** 业务id */
    businessId: number;
    /** 消费记录id  */
    consumeId: number;
    /** 消费目标  */
    consumeTitle: string;
    /** 消费类型：1-充值虚拟币；2-购买会员；3-购买剧集； */
    consumeType: 1 | 2 | 3;
    /** 创建时间 */
    createTime: string;
    /** 昵称  */
    nickname: string;
    /** 付费类型：1-现金；2-虚拟币； */
    payType: 1 | 2;
    /** 平台类型：1-抖音；2-快手；3-微信； */
    platformType: 1 | 2 | 3;
    /** 总金额 */
    totalAmount: number;
    /** app用户id */
    userId: number;
    /** 登录账号 */
    username: string;
};

export type AppUserSavings = {
    /** 创建时间  */
    createTime: string;
    /** 昵称 */
    nickname: string;
    /** 订单详情 */
    orderDetail: string;
    /** 订单id */
    orderId: number;
    /** 下单平台：mp-kuaishou-快手；mp-douyin-抖音；mp-weixin-抖音； */
    orderPlatform: 'mp-douyin' | 'mp-kuaishou' | 'mp-weixin';
    /** 订单名称  */
    orderSubject: string;
    /** 订单号 */
    outTradeNo: string;
    /** 支付渠道：WECHAT-微信；ALIPAY-支付宝；UNKNOWN-未知；*/
    payChannel: 'ALIPAY' | 'UNKNOWN' | 'WECHAT';
    /** 支付状态：-1-异常；0-待支付；1-已支付；2-支付失败；3-已退款；4-已关闭  */
    status: -1 | 0 | 1 | 2 | 3 | 4;
    /** 总金额 */
    totalAmount: number;
    /** 交易时间 */
    tradeTime: string;
    /** app用户id */
    userId: number;
    /** 登录账号 */
    username: string;
    /** 链接名称 */
    referralLinkName: string;
    /** 广告ID */
    promotionId?: string;
    /** 新 */
    registerTime?: string;
    backFlag?: string;
    thirdAdvertiserId?: string;
    firstOrRepeatRecharge?: string;
    rechargeCount?: string;
    __syncBackLoading: boolean;
};

export interface OrderTotalAmountDataItem {
    /**
     * 时间
     */
    dayTime?: string | null;
    /**
     * 总金额
     */
    totalAmount?: number | null;
    partnerUserAllTotalAmount?: number | null;
    /**
     * 短剧名称
     */
    dramaTitle?: number | null;
    /**
     * 合作方名称
     */
    partnerUserName?: number | null;
}

// 订单充值类型
export const orderTypeOptions = [
    {label: '充值K币', value: 1},
    {label: '购买会员', value: 2},
    {label: '购买剧集', value: 3},
    {label: '购买全集', value: 4},
    {label: 'K币解锁单集', value: 10},
    {label: '分享解锁', value: 11},
    {label: '权益券解锁', value: 12},
];

// 订单充值渠道
export const orderPayChannelOptions = [
    {label: '微信', value: 'WECHAT'},
    {label: '支付宝', value: 'ALIPAY'},
    {label: '抖音', value: 'DOUYIN'},
    {label: '抖音钻石', value: 'DOUYIN-DIAMOND'},
];
